// 节流
const throttleDirective = {
  mounted(el, binding) {
    const delay = parseInt(binding.value) || 300;
    let lastTime = 0;

    el.addEventListener("click", () => {
      const now = Date.now();
      if (now - lastTime > delay) {
        binding.value();
        lastTime = now;
      }
    });
    // 兼容手机端
    el.addEventListener("touchend", () => {
      const now = Date.now();
      if (now - lastTime > delay) {
        binding.value();
        lastTime = now;
      }
    });
  }
};

export default throttleDirective;

// 使用
// <button v-throttle="handleClick">点击</button>